apply plugin: 'groovy'

sourceCompatibility = $source_compatibility
version = '$init_version'
libPath = '$lib_path'
groovyHome = System.env.GROOVY_HOME
xmetaHome = System.env.XMETA_HOME

repositories {
    flatDir dirs: [libPath, "\$groovyHome/../groovy-$groovy_version/embeddable"]
}

dependencies {
    groovy ':groovy-all:$groovy_version'
    compile fileTree(dir: libPath, includes: ['*.jar'])
    compile fileTree(
        dir: "\$xmetaHome/lib/junit",
        includes: ['$junit_filename']
    )
}

jar {
    manifest {
        attributes 'Main-Class': '${package_name}.${main_class}'
        attributes 'Class-Path': new File(libPath).list().findAll {
            it.endsWith('.jar')
        }.collect { "\$libPath/\$it" }.join(' ') + 
        " \$libPath/groovy-all-${groovy_version}.jar"
    }
}

task dist(dependsOn: configurations.default.buildArtifacts) {
    delete 'dist'
    copy {
        into 'dist'
        from configurations.default.allArtifactFiles
    }

    copy {
        into "dist/\$libPath"
        from configurations.default
        exclude '$junit_filename'
    }

    copy {
        from '.'
        into 'dist'
        include 'LICENSE'
    }

    groovydoc
    copy {
        from 'build/docs'
        into 'dist'
    }
}
